//
//  AdjustPageView.m
//  SmartWatch
//
//  Created by zwj on 2022/11/25.
//

@interface AdjustTableCell : UITableViewCell

@property(nonatomic,strong) MyLinearLayout *root;
@end

@implementation AdjustTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if(self == [super initWithStyle: style reuseIdentifier:reuseIdentifier]){
        self.backgroundColor = COLOR_5;
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        MyLinearLayout *root = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
        root.myWidth = kScreenWidth;
        root.paddingTop = 15;
        root.cacheEstimatedRect = YES;
        root.myHeight = 100;
        [self.contentView addSubview:root];
        self.root = root;
        
        MyLinearLayout *backView = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
        backView.backgroundColor = COLOR_4;
        ViewCorner(backView, 10);
        backView.myHorzMargin = 15;
        backView.myHeight = 85;
        backView.padding = UIEdgeInsetsMake(10, 10, 10, 10);
        backView.subviewHSpace = 10;
        backView.gravity = MyGravity_Vert_Center;
        [root addSubview:backView];
        
        UIImageView *right = [[UIImageView alloc]initWithImage:UIImageMake(@"home_bg")];
        right.mySize = CGSizeMake(120, 72);
        [backView addSubview:right];
        
        UILabel *name = [UILabel createLabelText:@"中医保健操——肠清活力养生操" font:UIFontMake(15) textColor:COLOR1515];
        name.weight = 1;
        name.myHeight = kAutoHeight;
        [backView addSubview:name];
        
    }
    return self;
}

- (UIView *)addWeightView {
    UIView *view = [UIView new];
    view.weight = 1;;
    return view;
}

- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority
{
    if (@available(iOS 11.0, *)) {
       return [self.root sizeThatFits:CGSizeMake(targetSize.width - self.safeAreaInsets.left - self.safeAreaInsets.right, targetSize.height)];
    } else {
        return [self.root sizeThatFits:targetSize];
    }
}

@end


#import "AdjustPageView.h"


@interface AdjustPageView()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
@end

@implementation AdjustPageView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = BACKGROUNDCOLOR;
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
        self.tableView.dataSource = self;
        self.tableView.delegate = self;
        self.tableView.backgroundColor = COLOR_5;
        [self.tableView registerClass:[AdjustTableCell class] forCellReuseIdentifier:@"AdjustTableCell"];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.tableView.showsVerticalScrollIndicator = false;
        self.tableView.bounces = false;
        self.tableView.rowHeight = 100;
        [self addSubview:self.tableView];
        
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];

    self.tableView.frame = self.bounds;
}
#pragma mark - UITableViewDataSource, UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AdjustTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AdjustTableCell" forIndexPath:indexPath];
    return cell;
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (self.scrollCallback != nil) {
        self.scrollCallback(scrollView);
    }
    if (self.listScrollCallback != nil) {
        self.listScrollCallback(scrollView);
    }
}

#pragma mark - JXPagingViewListViewDelegate

- (UIScrollView *)listScrollView {
    return self.tableView;
}

- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
    self.scrollCallback = callback;
}

- (UIView *)listView {
    return self;
}

@end
